<?php
    $data = json_decode($_POST['data'], true);
    $nick = $data['nick'];
    $color = $data['color'];
    
    $old_login = $_COOKIE['login'];
    
    include "connect.php";
    
    $query = "UPDATE user SET login='$nick', color='$color' WHERE login = '$old_login'";
    $result = mysql_query($query)
        or die("query failed");

    $period = 7 * 24 * 60 * 60; //время хранения cookie
    setcookie('login', $nick, time() + $period);
    setcookie('color', $color, time() + $period);
    
    $_SESSION['login'] = $nick;
    $_SESSION['color'] = $color;
